package com.csx.governance.traffic.mq.rocketmq;

import org.apache.rocketmq.common.message.MessageExt;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @author cuisongxu
 * @date 2023/4/19 17:18
 */
@Aspect
public class RocketMqConsumeAspect {

    @Pointcut(value = "execution(* org.apache.rocketmq.spring.support.TrafficDefaultRocketMQListenerContainer.handleMessage(..))")
    public void pointcut(){};

    @Around(value = "pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) {

        Object[] args = joinPoint.getArgs();
        MessageExt clientRequest = (MessageExt) args[0];
        Object res = null;
        // 做前置处理
        System.out.println("做前置处理");
        try {
            res = joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        //
        System.out.println("做后置处理");
        return res;
    }
}
